<template>
  <nav class="navbar-dark bg-primary justify-content-between mb-4 px-4">
    <div class="w-75 mx-auto navbar">
      <router-link :to="{ name: 'Home' }" class="navbar-brand">
        Mine</router-link
      >
      <ul v-if="!user.nickName" class="list-inline mb-0">
        <li class="list-inline-item">
          <router-link
            :to="{ name: 'Login' }"
            class="btn btn-outline-light my-2"
            >登陆</router-link
          >
        </li>
        <li class="list-inline-item">
          <router-link
            :to="{ name: 'Signup' }"
            class="btn btn-outline-light my-2"
            >注册</router-link
          >
        </li>
      </ul>
      <ul v-else class="list-inline mb-0">
        <li class="list-inline-item">
          <dropdown :title="`你好 ${user.nickName}`">
            <dropdown-item>
              <router-link :to="{ name: 'Article' }" class="dropdown-item"
                >新建文章</router-link
              >
            </dropdown-item>
            <dropdown-item disabled>
              <router-link :to="{ name: 'Article' }" class="dropdown-item"
                >编辑资料</router-link
              >
            </dropdown-item>
            <dropdown-item @click="logout">
              <a class="dropdown-item">退出登录</a>
            </dropdown-item>
          </dropdown>
        </li>
      </ul>
    </div>
  </nav>
</template>
<script>
import Dropdown from './Dropdown';
import { useStore } from 'vuex';
import DropdownItem from './Dropdown/DropdownItem';
export default {
  name: 'GlobalHeader',
  components: { Dropdown, DropdownItem },
  props: {
    user: {
      type: Object,
      requird: true,
    },
  },
  setup() {
    const store = useStore();
    const logout = () => {
      store.dispatch('logout');
    };
    return {
      logout,
    };
  },
};
</script>
